const mongoose = require('mongoose'),
    DB_URL = 'mongodb://localhost:27017/wf_shop_wechat_pay';

// 设置useCreateIndex，以防警告
mongoose.set('useCreateIndex', true);

// 1. 连接
mongoose.connect(DB_URL, {
    useNewUrlParser: true,
    useUnifiedTopology: true
});

// 2. 连接成功
mongoose.connection.on('connected', () => {
    console.log('mongoose connection open to' + DB_URL);
});

// 3.连接异常
mongoose.connection.on('error', err => {
    console.log('mongoose connection error' + err);
});

// 4. 连接断开
mongoose.connection.on('disconnected', () => {
    console.log('mongoose connection disconnected');
});

module.exports = mongoose;
